package com.ruoyi.tester.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.tester.executor.expression.ExpressionContainer;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.security.PermitAll;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author SongJun
 * @description TODO:
 * @date 2022/5/18 14:00
 */
@Controller
@RequestMapping("/tester/util")
public class TesterUtilController extends BaseController {
    private String prefix = "tester/util";

    @GetMapping()
    public String translate_param()
    {
        return prefix + "/translate_param";
    }

    @GetMapping("/expressions")
    public String expressions(ModelMap mmap)
    {
        List<String> expDescList = ExpressionContainer.expressionsDescription();
//        String expDesc = expDescList.stream().collect(Collectors.joining("\r\n"));
        mmap.put("expressions", expDescList);
        return prefix + "/expressions";
    }

    @GetMapping("/delay")
    @ResponseBody
    @PermitAll
    public AjaxResult delay(long second){
        try {
            Thread.sleep(second * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return toAjax(true);
    }
}
